
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:image_picker/image_picker.dart';
import 'Mine.dart';
class Todo{                    //传值
  Key key;
  String name='小明';
  String TxUrl = '';
  bool HaveTX;
  Todo(this.name,this.TxUrl,this.HaveTX);
}

class personal extends StatefulWidget {
  @override
  personalState createState() => new personalState();

}

void main(){
    runApp(MaterialApp(home: personal(),routes: {'Mine':(context)=>Mine()},),);
}


class personalState extends State<personal> {
  bool HaveTX = false;
  String username = '小明';
  var PhoneNumber = '15688888888';
  String ImgUrl = '';
  String sex='男';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        resizeToAvoidBottomPadding: false,
        appBar: AppBar(
            backgroundColor: Color.fromRGBO(51, 51, 51, 1),
            titleSpacing: 0.0,
            title:Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                FlatButton(
                  materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                  child: Row(
                    children: [
                      Icon(Icons.arrow_back_ios,color: Colors.white,),
                      Text('返回',style: TextStyle(color: Colors.white,fontSize: 16),)
                    ],
                  ),
                  onPressed: (){
                    Navigator.pop(context);
                  },
                ),
                Container(child: Row(children: [
                  Text('个人信息',style: TextStyle(fontSize: 16),),
                  SizedBox(width: 25,)
                ],),),
                IconButton(icon: Icon(Icons.more_horiz), onPressed: (){})
              ],
            )
        ),
        body: Container(
          color: Colors.grey.withOpacity(0.25),
          child: Column(
            children: <Widget>[
              Container(
                color: Colors.white,
                child: Column(
                  children: <Widget>[
                    GestureDetector(
                      onTap: (){
                        //换头像
                        showModalBottomSheet(context: context,
                            builder: (builder){
                              return Container(
                                height: 180.0,
                                // color: Colors.transparent, //could change this to Color(0xFF737373),
                                child: Container(
                                    decoration: new BoxDecoration(
                                        color: Colors.white,
                                    ),
                                    child: Column(
                                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                      children: [
                                       Container(
                                         height: 10,
                                         margin: EdgeInsets.only(right: 30,top: 10),
                                         alignment: Alignment.centerRight,
                                         child:  GestureDetector(
                                           onTap: (){
                                             Navigator.pop(context);
                                           },
                                           child: Icon(Icons.close),
                                         ),
                                       ),
                                        Container(
                                          alignment: Alignment.topCenter,
                                          margin: EdgeInsets.only(bottom: 10),
                                          child: Text('更换头像',style: TextStyle(fontSize: 20),),
                                        ),

                                        Divider(thickness: 1,height: 1,color: Colors.black12,),

                                        Container(
                                          child: GestureDetector(
                                            child: Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceAround,
                                              children: [
                                                Icon(Icons.camera_alt),
                                                Text('相机拍照',style: TextStyle(fontSize: 20),),
                                              ],
                                            ),
                                            onTap: (){
                                              getImage();
                                              HaveTX = !HaveTX;
                                              Navigator.pop(context);
                                            },
                                          ),
                                        ),

                                        Divider(thickness: 1,height: 1,color: Colors.black12,),

                                        Container(
                                            child: GestureDetector(
                                              child: Row(
                                                mainAxisAlignment: MainAxisAlignment.spaceAround,
                                                children: [
                                                  Icon(Icons.credit_card),
                                                  Text('本地相册',style: TextStyle(fontSize: 20),),
                                                ],
                                              ),
                                              onTap: (){
                                                chooseImage();
                                                HaveTX = !HaveTX;
                                                Navigator.pop(context);
                                              },
                                            )
                                        ),
                                        SizedBox(height: 5,),
                                      ],
                                    ),
                                ),
                              );
                            }
                        );
                        print('进入换头像');
                      },
                      child: Container(
                        // width: Size.infinite.width,
                        decoration: BoxDecoration(
                          //...
                        ),
                        child: Row(
                          children: <Widget>[
                            Container(
                              width: 70,
                              height: 70,
                              margin: EdgeInsets.only(top: 20,left: 20),
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                border:
                                Border.all(width: 1, color: Colors.grey.withOpacity(0.9)),
                                borderRadius: BorderRadius.circular(75),
                                color: Colors.white,
                              ),
                              child: tx(),   //头像
                            ),
                            Container(
                              margin: EdgeInsets.only(top: 20,left: 30),
                              child:Text(username) ,
                            ),


                          ],
                        ),

                      ),
                    ),
                    Divider(indent: 20,endIndent: 20,height: 10,color: Colors.black12,thickness: 1.5,),

                    //姓名输入框
                    Container(
                      margin: EdgeInsets.only(left: 10),
                      child: Row(
                        children: <Widget>[
                          Text('*',style: TextStyle(color: Colors.red),),
                          Text('  姓名:  '),
                          Container(
                            width: 280,
                            child:TextField(
                              decoration: InputDecoration(
                                  labelStyle: TextStyle(color:Colors.black),
                                  hintText: '请输入用户名'
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),

                    // Divider(indent: 20,endIndent: 20,height: 10,color: Colors.black12,thickness: 1.5,),

                    //性别下拉框
                    Container(
                      margin: EdgeInsets.only(left: 10),
                      child:  Row(
                        children: <Widget>[
                          Text('*',style: TextStyle(color: Colors.red),),
                          Text('  性别:  '),
                          Container(
                            child:DropdownButton(
                              value: sex,
                              items: [
                                DropdownMenuItem(child: Text('男'),value: '男',),
                                DropdownMenuItem(child: Text('女'),value: '女',),
                                DropdownMenuItem(child: Text('不详'),value: '不详',),
                              ],
                              onChanged: (value){
                                setState(() {
                                  sex = value;
                                  // print(sex);
                                });
                              },
                            ),
                          ),
                        ],
                      ),
                    ),

                    // Divider(indent: 20,endIndent: 20,height: 10,color: Colors.black12,thickness: 1.5,),

                    SizedBox(height: 10,),
                    //手机号
                    Container(
                      margin: EdgeInsets.only(left: 25),
                      child: Row(
                        children: <Widget>[
                          Text('手机号：'),
                          Text(PhoneNumber)
                        ],
                      ),
                    ),
                    Divider(indent: 20,endIndent: 20,height: 10,color: Colors.black12,thickness: 1.5,),
                    //学校
                    Container(
                      margin: EdgeInsets.only(left: 10,top: 10,bottom: 70),
                      child: Row(
                        children: <Widget>[
                          Text('*',style: TextStyle(color: Colors.red),),
                          Text('  学校:  '),

                          Container(
                            width: 280,
                            child:TextField(
                              decoration: InputDecoration(
                                  labelStyle: TextStyle(color:Colors.black),
                                  hintText: '请输入学校'
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            Spacer(),
            Container(
              width: Size.infinite.width,
              child: GestureDetector(
                child: Container(
                  color: Color.fromRGBO(153, 153, 153, 1),
                  child: FlatButton(
                    child: Text('确认修改',style: TextStyle(color: Colors.white),),
                  ),
                ),
                onTap: (){
                  Todo todo = Todo(username,ImgUrl,HaveTX);
                  Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context)=>Mine(todo: todo))
                  );
                },
              ),
            ),


            ],
          ),
        ),

      ),
    );

  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  //头像
  tx() {
    if(HaveTX == false){
      return Text('头像');
    }else{
      //换头像
      return Container(
          width: 70,
          height: 70,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(75),
            color: Colors.white,
          ),
        child:ClipOval(
            child: Image.asset(ImgUrl,fit:BoxFit.cover,width: 70,height: 70,)
        )
      );

    }
  }
Future getImage() async {
    // ignore: deprecated_member_use 选择照片, deprecated_member_use
    await ImagePicker.pickImage(source: ImageSource.camera)
        .then((image){
      setState(() {

        ImgUrl = image.path;
        print('文件路径是：'+ImgUrl);
        HaveTX = true;
      }

      );
    }
    );
  }           //自己拍照

  Future chooseImage() async {
    // ignore: deprecated_member_use

    await ImagePicker.pickImage(source: ImageSource.gallery)
        .then((image) {

          setState(() {
            ImgUrl = image.path;
            print('文件路径是：'+ImgUrl);
            HaveTX = true;
          }
          );

    });
  }     //从相册选择照片







}
